package dao.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.DepartmentDao;
import entity.Department;

public class DepartmentDaoImpl extends HibernateDaoSupport implements DepartmentDao {

	public List<Department> queryAll() {
		return this.getHibernateTemplate().find("from Department");
	}

	public int calCount() {
		List<Long> list = this.getHibernateTemplate().find("select count(*) from Department");
		return list.get(0).intValue();
	}

	public List<Department> findByPage(int begin, int pageSize) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Department.class);
		return this.getHibernateTemplate().findByCriteria(criteria, begin, pageSize);
	}

	public void save(Department department) {
		this.getHibernateTemplate().save(department);
	}

	public Department findById(Integer did) {
		return this.getHibernateTemplate().get(Department.class, did);
	}

	public void update(Department department) {
		this.getHibernateTemplate().update(department);
	}

	public void delete(Department department) {
		this.getHibernateTemplate().delete(department);
	}

	public List<Department> findAll() {
		return this.getHibernateTemplate().find("from Department");
	}

}
